class T {
public:
    bool operator()(pair<int, int>& p1, pair<int, int> p2) {
        if(p1.second == p2.second){
            return p1.first > p2.first;
        }
        return p1.second > p2.second;
    }
};
class Solution {
public:
    vector<int> getFinalState(vector<int>& nums, int k, int multiplier) {
        priority_queue < pair<int, int>, vector<pair<int, int>>, T> pq;
        for (int i = 0; i < nums.size(); i++) {
            pq.push({i, nums[i]});
        }
        while(k--){
            auto e = pq.top();
            pq.pop();
            e.second*= multiplier;
            pq.push(e);
        }
        while(!pq.empty()){
            auto e = pq.top();
            nums[e.first] = e.second;
            pq.pop();
        }
        return nums;
    }
};